import BaseInputEvent from "../TvBox/BaseInputEvent";
import GuideEvent from "../TvBox/GuideEvent";
import LeaveGameEvent from "../TvBox/LeaveGameEvent";
import PauseEvent from "../TvBox/PauseEvent";
import TvBoxButtonListEvent from "../TvBox/TvBoxButtonListEvent";
import TvBoxInput from "../TvBox/TvBoxInput";
import TexTipsShow from "./TexTipsShow";

const { ccclass } = cc._decorator;
@ccclass
export default class MonoSingle<T>  extends cc.Component {


    private static instances = new Map();
    static canvasNode: cc.Node = null;
    static Reset() {
        MonoSingle.instances = new Map();
        MonoSingle.canvasNode = null;
    }
    public static GetBaseInputEvent(): BaseInputEvent {
        if (MonoSingle.canvasNode == null)
            MonoSingle.canvasNode = cc.find("Canvas");
        let component = BaseInputEvent;
        if (!this.instances.has(component)) {
            this.instances.set(BaseInputEvent, MonoSingle.canvasNode.getComponentInChildren(component))
        }
        if (!this.instances.has(component))
            cc.error("没有注册组件::" + component.name);
        return this.instances.get(component);
    }
    public static GetGuideEvent(): GuideEvent {
        if (MonoSingle.canvasNode == null)
            MonoSingle.canvasNode = cc.find("Canvas");
        let component = GuideEvent;
        if (!this.instances.has(component)) {
            this.instances.set(GuideEvent, MonoSingle.canvasNode.parent.getComponentInChildren(component))
        }
        if (!this.instances.has(component))
            cc.error("没有注册组件::" + component.name);
        return this.instances.get(component);
    }

    public static GetLeaveGameEvent(): LeaveGameEvent {
        if (MonoSingle.canvasNode == null)
            MonoSingle.canvasNode = cc.find("Canvas");
        let component = LeaveGameEvent;
        if (!this.instances.has(component)) {
            this.instances.set(LeaveGameEvent, MonoSingle.canvasNode.parent.getComponentInChildren(component))
        }
        if (!this.instances.has(component))
            cc.error("没有注册组件::" + component.name);
        return this.instances.get(component);
    }

    public static GetTvBoxButtonListEvent(): TvBoxButtonListEvent {
        if (MonoSingle.canvasNode == null)
            MonoSingle.canvasNode = cc.find("Canvas");
        let component = TvBoxButtonListEvent;
        if (!this.instances.has(component)) {
            this.instances.set(TvBoxButtonListEvent, MonoSingle.canvasNode.getComponentInChildren(component))
        }
        if (!this.instances.has(component))
            cc.error("没有注册组件::" + component.name);
        return this.instances.get(component);
    }

    public static GetTvBoxInput(): TvBoxInput {
        if (MonoSingle.canvasNode == null)
            MonoSingle.canvasNode = cc.find("Canvas");
        let component = TvBoxInput;
        if (!this.instances.has(component)) {
            this.instances.set(TvBoxInput, MonoSingle.canvasNode.getComponentInChildren(component))
        }
        if (!this.instances.has(component))
            cc.error("没有注册组件::" + component.name);
        return this.instances.get(component);
    }

    public static GetPauseEvent(): PauseEvent {
        if (MonoSingle.canvasNode == null)
            MonoSingle.canvasNode = cc.find("Canvas");
        let component = PauseEvent;
        if (!this.instances.has(component)) {
            this.instances.set(PauseEvent, MonoSingle.canvasNode.getComponentInChildren(component))
        }
        if (!this.instances.has(component))
            cc.error("没有注册组件::" + component.name);
        return this.instances.get(component);
    }

	public static ShowTips(tips):void  {
		if (MonoSingle.canvasNode == null)
			MonoSingle.canvasNode = cc.find("Canvas");
		var texTipsShow = MonoSingle.canvasNode.getComponentInChildren(TexTipsShow);
		if (texTipsShow!= null)
		{
			texTipsShow.getComponent
			texTipsShow.node.destroy();
		}
		
		cc.loader.loadRes("tvboxPrefabs/tex_tips_show", cc.Prefab, function name(error, prefab) {
			let temp = cc.instantiate(prefab);
			cc.error(temp)
			temp.setParent(MonoSingle.canvasNode); 
			temp.getComponent(TexTipsShow).showTips(tips)
		});
	}


}


